package com.xxxxx.Servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/*
 * 	request作用域
 * 		通过该对象可以在一个请求中传递数据,作用范围: 在一次请求中有效,即服务器跳转有效。(请求转发跳转时有效)
 * 		//设置域对象内容
 * 		request.setAttribute(String name,Object value);
 * 		//获取域对象内容
 * 		request.getAttribute(String name);
 * 		//删除域对象内容
 * 		request.removeAttibute(String name);
 */



@WebServlet("/S8")
public class TestServlet08 extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("Servlet08.....");
		
		//设置域对象的内容
		request.setAttribute("name","zhangsan");
		request.setAttribute("age", 18);
		List<String> list = new ArrayList<>();
		list.add("aaa");
		list.add("bbb");
		request.setAttribute("list", list);
		
		//请求转发跳转到Servlet09
		//request.getRequestDispatcher("S9").forward(request, response);
		//请求转发跳转到index.jsp
		request.getRequestDispatcher("index.jsp").forward(request, response);
		
	}
		
}
